<?php

require_once('../../includes/classes/core.php');
$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

switch ($action) {
	case 'get_list' :
		$count = 		$_REQUEST['count'];
		$hidden = 		$_REQUEST['hidden'];
		$start		= $_REQUEST['start'];
		$end		= $_REQUEST['end'];
		$dep_id     = $_REQUEST['dep_id'];
		
		if($dep_id == 0){
		    $dep_check = '';
		}else{
		    $dep_check = "AND users.dep_id = '$dep_id'";
		}
	  	$rResult = mysql_query("SELECT  asterisk_incomming.id,
                        				asterisk_incomming.datetime,
                        				asterisk_incomming.source,
                        				asterisk_incomming.dst_queue,
                        				asterisk_incomming.dst_extension,
                        				SEC_TO_TIME(asterisk_incomming.wait_time),
                        				SEC_TO_TIME(asterisk_incomming.duration),
                        				CONCAT('<button style=\"width:100%; margin:5px 0;\" class=\"lisen ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover\" onclick=\"play(\'',file_name,'\')\" ><span class=\"ui-button-text\">მოსმენა</span></button>') AS `rec`
                                FROM `asterisk_incomming`
                                JOIN users ON asterisk_incomming.user_id = users.id
                                WHERE 
                                dst_queue IN('10400','10500','1100','1200','1300','1400','1500','1600','1700','1800','1900','2200404','2404004','103000','104000','10800','10880')
                                AND dst_extension IN('Call Center 1','Call Center 2','Call Center 3','Call Center 4','Confidencial','Gazifikacia','Kancelaria','Sadispechero','Combit','Samgori Op','Samgori tex','Isani Op','Isani Tex','Didube Op','Didube Tex','Didube Tex2','Sanzona Op','Sanzona Tex','Gldani Op','Nadzaladevi Op','Nadzaladevi Tex','Gldani Tex','Saburtalo Op','Saburtalo Tex','Nutsubidze Op','Nutsubidze Tex','Vake Op','Vake Tex','Mtatsminda Op','Mtatsminda Tex','Digomi Op','Digomi Tex','IT Irakli')
                                AND disconnect_cause != 'ABANDON'
                                AND DATE(datetime) >= '$start' AND DATE(datetime) <= '$end'
                                AND ISNULL(inc_id)
                                $dep_check");
	  
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
			}
			$data['aaData'][] = $row;
		}

		break;
		
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);

?>